var prefix = ctx + "module/order"

$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'orderId', 
			title : '订单id' 
		},
				{
			field : 'orderNum', 
			title : '订单号' 
		},
				{
			field : 'orderStatus',
			title : '订单状态',
			formatter : function(value, row, index) {
				if (value == 0) {
					return '<span class="label">待分配</span>';
				} else {
					return '<span class="label">待跟进</span>';
				}
			}
		},
				{
			field : 'typeName', 
			title : '订单类型' 
		},
				{
			field : 'createBy', 
			title : '跟进客服' 
		},
				{
			field : 'createTime', 
			title : '订单创建时间' 
		},
		        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
				actions.push('<a class="btn btn-primary btn-sm ' + detailsFlag + '" href="#" title="派单" mce_href="#" onclick="details(\'' + row.orderId + '\')"><i class="fa fa-hand-pointer-o"></i></a> ');
				/*actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i></a>');*/
				return actions.join('');
            }
        }];
	var url = prefix + "/dispatchDeptList";
	$.initTable(columns, url);
});

/*订单-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增订单", url);
}

/*订单-详情*/
function details(orderId) {
    var url = prefix + '/dispatchDeptDetails/' + orderId;
    layer_showAuto("订单详情", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中订单吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("orderId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
